authApp.value('page','investiga');

authApp.controller("expertListController",function($scope,$http,page,$chineseNum){
	$scope.isAddM=true;
	$scope.isHExpert=true;
	$scope.isMLExpert=true;
	$scope.schoolId="";
	$scope.zjlist=[];
	$scope.addM=function(pid,index){
		$scope.schoolNow=$scope.list[index].schoolName;
		$scope.isAddM=false;
		$scope.schoolId=pid;
	}
	$scope.isEmptyObject=function( obj ) {
		for ( var name in obj ) {
			return false;
		}
		return true;
	}
	$scope.cancelAddM=function(){
		$scope.isAddM=true;
		$scope.addFZ="";
		if($scope.llylist&&!$scope.isEmptyObject($scope.llylist)){
			$scope.lastexpertList.push($scope.llylist);
		}
		if($scope.zzlist&&!$scope.isEmptyObject($scope.zzlist)){
			$scope.lastexpertList.push($scope.zzlist);
		}
		if($scope.zjlist.length>0){
			$scope.lastexpertList=$scope.lastexpertList.concat($scope.zjlist);
		}
		$scope.llylist={};
		$scope.zzlist={};
		$scope.zjlist=[];
		$scope.isllyChoose="";
		$scope.iszjChoose="";
		$scope.iszzChoose="";
	}
	$scope.addFirstZ=function(){
		if(window.confirm("是否确认添加")){
			var typeStr="0,2,";
			var expertNameStr=$scope.zzlist.pid+","+$scope.llylist.pid+","
			angular.forEach($scope.zjlist,function(data,index,array){
				if(index!=(array.length-1)){
					typeStr+="1,";
					expertNameStr+=data.pid+",";
				}else{
					typeStr+="1";
					expertNameStr+=data.pid;
				}
			})
			var rJson={
						'sid':$scope.schoolId,
						'expertid':expertNameStr,
						'expertType':typeStr
						};
			$http({
				method:'post',
				url:apis.insertAuthSchoolExpertMap,
				data:rJson,
			}).success(function(response){
				if(response.code=="000000"){
					location.reload();
				}else{
					alert(response.errorMsg);
				}
			}).error(function(){
				alert("服务器打瞌睡了，请稍等！");
				$scope.isAddM=true;
			})
		}
	}
	$scope.unbindSchool=function(pid){
		if(window.confirm("是否确认解绑？")){
			$http({
				method:'post',
				url:apis.queryAuthSchool,
				data:{'pageNumber':1,'pageSize':'100','review':'1'}
			}).success(function(response){
				if(response.code=="000000"){
					$scope.list=response.data.data;
				}else{
					alert(response.errorMsg);
				}
			}).error(function(){
				alert("服务器打瞌睡了，请稍等！");
				$scope.isAddM=true;
			})
		}
		alert(pid);
	}
	$scope.getList=function(){
		if($scope.isHExpert){
			type=0;
		}else{
			type=1;
		}
		$http({
			method:'post',
			url:apis.queryAuthSchool,
			data:{'pageNumber':1,'pageSize':'100','review':'1'}
		}).success(function(response){
			if(response.code=="000000"){
				$scope.list=response.data.data;
			}else{
				alert(response.errorMsg);
			}
		}).error(function(){
			alert("服务器打瞌睡了，请稍等！");
			$scope.isAddM=true;
		})
	}
	$scope.getList();
	$scope.getExpertList=function(){
		$http({
			method:'post',
			url:apis.queryAuthExpert,
			data:{'status':'0'}
		}).success(function(response){
			if(response.code=="000000"){
				$scope.lastexpertList=response.data;
			}else{
				alert(response.errorMsg);
			}
		}).error(function(){
			alert("服务器打瞌睡了，请稍等！");
			$scope.isAddM=true;
		})
	}
	$scope.getExpertList();
	$scope.chooseAddExpertType=function(type){
		if(type=="lly"){
			$scope.expert="lly";
			$scope.isllyChoose="hasChoose";
			$scope.iszzChoose="";	
			$scope.iszjChoose="";
		}
		if(type=="zz"){
			$scope.expert="zz";
			$scope.iszzChoose="hasChoose";
			$scope.isllyChoose="";
			$scope.iszjChoose="";
				}
		if(type=="zj"){
			$scope.expert="zj";
			$scope.iszjChoose="hasChoose";	
			$scope.isllyChoose="";
			$scope.iszzChoose="";
		}
	}
	$scope.chooseOneExpert=function(index){
		if($scope.expert=="lly"){
			if($scope.llylist&&$scope.llylist.length>0){
				var xxxlist=$scope.llylist;
				$scope.llylist=$scope.lastexpertList[index];
				$scope.lastexpertList.splice(index,1);
				$scope.lastexpertList.push(xxxlist);
				
			}else{
				$scope.llylist=$scope.lastexpertList[index];
				$scope.lastexpertList.splice(index,1);
			}
		}
		if($scope.expert=="zz"){
			if($scope.llylist&&$scope.llylist.length>0){
				var xxxlist=$scope.zzlist;
				$scope.zzlist=$scope.lastexpertList[index];
				$scope.lastexpertList.splice(index,1);
				$scope.lastexpertList.push(xxxlist);
				
			}else{
				$scope.zzlist=$scope.lastexpertList[index];
				$scope.lastexpertList.splice(index,1);
			}
		}
		if($scope.expert=="zj"){
			$scope.zjlist.push($scope.lastexpertList[index]);
			$scope.lastexpertList.splice(index,1);
		}
	}
})